import 'package:FineArt/constants.dart';
import 'package:FineArt/utils/size_config.dart';
import 'package:badges/badges.dart';
import 'package:flutter/material.dart';

class DiscoveryPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _DiscoveryPageState();
  }
}

class _DiscoveryPageState extends State<DiscoveryPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("发现",
            style: TextStyle(color: text_black, fontSize: setSp(18))),
        backgroundColor: Colors.white,
        automaticallyImplyLeading: false,
        centerTitle: true,
        brightness: Brightness.light,
        elevation: 0,
      ),
      body: Column(
        children: [
          buildCommonItem("assets/images/icon_actical_news.png", "美术头条", () {}, null),
          buildCommonItem("assets/images/icon_ability.png", "能力测评", () {}, null),
          buildCommonItem("assets/images/icon_guider.png", "报考指南", () {}, null),
          buildCommonItem("assets/images/icon_sign_up.png", "志愿填报", () {}, null),
        ],
      ),
    );
  }


  //构建通用item
  Widget buildCommonItem(
      String name, String itemContent, Function clickListener, noticeCount) {
    return InkWell(
      child: Container(
        color: Colors.white,
        margin: EdgeInsets.fromLTRB(16, 1, 16, 0),
        padding:
        EdgeInsets.only(left: getPortraitSWidth(15), right:  getPortraitSWidth(15), bottom: getPortraitSHeight(12), top: getPortraitSHeight(12)),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Image.asset(
              name,
              width: getPortraitSWidth(18.5),
              height: getPortraitSHeight(19.5),
            ),
            Expanded(
              child: Padding(
                padding: EdgeInsets.only(left: 20.0),
                child: getBadgeText(itemContent, noticeCount),
              ),
            ),
            Image.asset(
              "assets/images/icon_right_arrow.png",
              width: getPortraitSWidth(7.5),
              height: getPortraitSHeight(13),
            ),
          ],
        ),
      ),
      onTap: clickListener,
    );
  }
  Widget getBadgeText(String name, String count) {
    if (count == null) {
      return Text(
        name,
        style: TextStyle(color: Colors.black87),
      );
    }
    return Container(
        width: 20,
        child: Badge(
          badgeContent: Text(
            count,
            style: TextStyle(color: Colors.white),
          ),
          child: Text(
            name,
            style: TextStyle(color: text_black,fontSize: setSp(16)),
          ),
        ));
  }
}
